<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
        protected function _initAutoLoad ()
        {
            require_once 'ChecagemDeAcesso.php';
            require_once 'acl/Acl_Library.php';
           
//            if( !($acl = Core_Acl::cacheLoad ('Core_Acl')) )
//            {
//                $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/acl.xml');
           //     print_r($config); exit;
//                $acl = new Core_Acl ($config);
            
             $acl = new Core_Acl ();
             
             
//                echo 'depois'; exit;
//                Core_Acl::cacheSave ('Core_Acl', $acl);
//                $acl = Core_Acl::cacheLoad ('Core_Acl');
//            }

            Zend_Registry::set('acl', $acl);

            
            $auth = Zend_Auth::getInstance ();

            $fc   = Zend_Controller_Front::getInstance ();

            $fc->registerPlugin (new Plugin_ChecagemDeAcesso ($acl, $auth));
           
        }

        protected function _initResources()
        {   
            $loader = $this->getResourceLoader();
            $loader->addResourceType('filter', 'filters', 'Filter');
            
        }

        public function __construct ($application)
	{       
                parent::__construct ($application);
		 		$this->openDBConnection();
				$this->createSessionNamespace();
				$this->createInputFilters();

	}

//        protected function _initAcl()
//        {
//            $aclSetup = new Model_Acl();
//        }

        
	private function openDBConnection()
	{
	      $databases = new Zend_Config_Ini(APPLICATION_PATH.'/configs/db.ini','database');

              foreach ($databases->db as $config_name => $db )
              {

                $dbAdapters[$config_name] = Zend_Db::factory($db->adapter,$db->config->toArray());
		if((boolean)$db->default)
                    Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapters[$config_name]);

              }

              Zend_Registry::set('dbAdapters', $dbAdapters);


	}

	private function createSessionNamespace()
	{
		Zend_Registry::set('session',new Zend_Session_Namespace('session'));
	}

	private function createInputFilters()
	{
		Zend_Registry::set('get',new Zend_Filter_Input(null,null,$_GET));
		Zend_Registry::set('post',new Zend_Filter_Input(null,null,$_POST));
	}



}
